using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using PHMEE.Managers.Diagnosis;
using PHMEE.PHM.Algorithms.Diagnosis;

namespace PHMEE.Services.Diagnosis;

public static class TestDataProvider
{
    public static IEnumerable<object[]> GetJsonData(string filesDict, Type type)
    {
        var filePaths = Directory.GetFiles(filesDict, "*.json");

        Dictionary<string, string[]> faultCodes;
        
        switch (type.Name)
        {
            case nameof(MainLubricatingOilPumpFaultDiagnosisDomainService):
                faultCodes = MainLubricatingOilPumpFaultCodes;
                break;
            case nameof(AirCompressorFaultDiagnosisDomainService):
                faultCodes = AirCompressorFaultCodes;
                break;
            case nameof(OilFuelSeparatorFaultDiagnosisDomainService):
                faultCodes = OilFuelSeparatorFaultCodes;
                break;
            case nameof(AirBlower1Service):
                faultCodes = AirBlower1FaultCodes;
                break;
            case nameof(AirBlower2Service):
                faultCodes = AirBlower2FaultCodes;
                break;
            case nameof(TurbineFaultDiagnosisDomainService):
                faultCodes = TurbineFaultCodes;
                break;
            case nameof(DieselGeneratorFaultDiagnosisDomainService):
                faultCodes = DieselGeneratorFaultCodes;
                break;
            default:
                throw new ArgumentException("Invalid type");
        }
        
        foreach (var filePath in filePaths)
        {
            var json = File.ReadAllText(filePath);
            var data = JsonSerializer.Deserialize<JianLongDataModel>(json, new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true
            });

            if (data is not null)
            {
                var fileName = Path.GetFileNameWithoutExtension(filePath);

                var memberDataModelAccX = new TestMemberDataModel
                {
                    FileName = fileName,
                    Direction = "AccX",
                    Acc = data.AccX,
                    Fs = data.Fs,
                    FaultCodes = faultCodes[fileName + "_AccX"]
                };
                var memberDataModelAccY = new TestMemberDataModel
                {
                    FileName = fileName,
                    Direction = "AccY",
                    Acc = data.AccY,
                    Fs = data.Fs,
                    FaultCodes = faultCodes[fileName + "_AccY"]
                };
                var memberDataModelAccZ = new TestMemberDataModel
                {
                    FileName = fileName,
                    Direction = "AccZ",
                    Acc = data.AccZ,
                    Fs = data.Fs,
                    FaultCodes = faultCodes[fileName + "_AccZ"]
                };

                yield return [memberDataModelAccX];
                yield return [memberDataModelAccY];
                yield return [memberDataModelAccZ];
            }
        }
    }
    
    private static readonly Dictionary<string, string[]> MainLubricatingOilPumpFaultCodes = new()
    {
        { "1659374030_AccX", ["RB-1"] },
        { "1659374030_AccY", ["RB-2", "RB-1"] },
        { "1659374030_AccZ", ["no_fault"] },
        { "1659381230_AccX", ["RB-1"] },
        { "1659381230_AccY", ["RB-2", "RB-1"] },
        { "1659381230_AccZ", ["no_fault"] },
        { "1659388431_AccX", ["RB-2", "RB-1"] },
        { "1659388431_AccY", ["RB-2", "RB-1"] },
        { "1659388431_AccZ", ["no_fault"] },
        { "1659395630_AccX", ["RB-2", "RB-1"] },
        { "1659395630_AccY", ["no_fault"] },
        { "1659395630_AccZ", ["no_fault"] },
        { "1659402830_AccX", ["RB-2", "RB-1"] },
        { "1659402830_AccY", ["RB-2", "RB-1"] },
        { "1659402830_AccZ", ["no_fault"] },
        { "1659410030_AccX", ["RB-2", "RB-1"] },
        { "1659410030_AccY", ["RB-2", "RB-1"] },
        { "1659410030_AccZ", ["no_fault"] },
        { "1659417230_AccX", ["RB-2", "RB-1"] },
        { "1659417230_AccY", ["RB-2", "RB-1"] },
        { "1659417230_AccZ", ["no_fault"] },
        { "1659424431_AccX", ["RB-2", "RB-1"] },
        { "1659424431_AccY", ["RB-2", "RB-1"] },
        { "1659424431_AccZ", ["no_fault"] },
        { "1659431630_AccX", ["RB-2", "RB-1"] },
        { "1659431630_AccY", ["RB-2", "RB-1"] },
        { "1659431630_AccZ", ["no_fault"] },
        { "1659438831_AccX", ["RB-2", "RB-1"] },
        { "1659438831_AccY", ["RB-2", "RB-1"] },
        { "1659438831_AccZ", ["no_fault"] },
        { "1659446031_AccX", ["RB-2", "RB-1"] },
        { "1659446031_AccY", ["RB-2", "RB-1", "Fluid-1"] },
        { "1659446031_AccZ", ["no_fault"] },
        { "1659453230_AccX", ["RB-2", "RB-1"] },
        { "1659453230_AccY", ["RB-2", "RB-1"] },
        { "1659453230_AccZ", ["no_fault"] },
        { "1659460430_AccX", ["RB-2", "RB-1"] },
        { "1659460430_AccY", ["RB-2", "RB-1"] },
        { "1659460430_AccZ", ["no_fault"] },
        { "1659467630_AccX", ["RB-2", "RB-1"] },
        { "1659467630_AccY", ["RB-2", "RB-1"] },
        { "1659467630_AccZ", ["RB-2", "RB-1"] },
        { "1659474831_AccX", ["RB-2", "RB-1"] },
        { "1659474831_AccY", ["RB-2", "RB-1"] },
        { "1659474831_AccZ", ["no_fault"] },
        { "1659482030_AccX", ["RB-2", "RB-1"] },
        { "1659482030_AccY", ["RB-2", "RB-1"] },
        { "1659482030_AccZ", ["RB-1"] },
    };

    private static readonly Dictionary<string, string[]> AirCompressorFaultCodes = new()
    {
        { "1659374030_AccX", ["Recip-2", "Recip-4"] },
        { "1659374030_AccY", ["no_fault"] },
        { "1659374030_AccZ", ["no_fault"] },
        { "1659381230_AccX", ["no_fault"] },
        { "1659381230_AccY", ["no_fault"] },
        { "1659381230_AccZ", ["no_fault"] },
        { "1659388431_AccX", ["no_fault"] },
        { "1659388431_AccY", ["no_fault"] },
        { "1659388431_AccZ", ["no_fault"] },
        { "1659395630_AccX", ["no_fault"] },
        { "1659395630_AccY", ["no_fault"] },
        { "1659395630_AccZ", ["no_fault"] },
        { "1659402830_AccX", ["Recip-2", "Recip-4"] },
        { "1659402830_AccY", ["no_fault"] },
        { "1659402830_AccZ", ["no_fault"] },
        { "1659410030_AccX", ["no_fault"] },
        { "1659410030_AccY", ["no_fault"] },
        { "1659410030_AccZ", ["no_fault"] },
        { "1659417230_AccX", ["Recip-2", "Recip-4"] },
        { "1659417230_AccY", ["no_fault"] },
        { "1659417230_AccZ", ["no_fault"] },
        { "1659424431_AccX", ["Recip-2", "Recip-4"] },
        { "1659424431_AccY", ["Recip-2", "Recip-4"] },
        { "1659424431_AccZ", ["no_fault"] },
        { "1659431630_AccX", ["Recip-2", "Recip-4"] },
        { "1659431630_AccY", ["Recip-2", "Recip-4"] },
        { "1659431630_AccZ", ["no_fault"] },
        { "1659438831_AccX", ["Recip-2", "Recip-4"] },
        { "1659438831_AccY", ["Recip-2", "Recip-4"] },
        { "1659438831_AccZ", ["no_fault"] },
        { "1659446031_AccX", ["Recip-2", "Recip-4"] },
        { "1659446031_AccY", ["Recip-2", "Recip-4"] },
        { "1659446031_AccZ", ["no_fault"] },
        { "1659453230_AccX", ["Recip-2", "Recip-4"] },
        { "1659453230_AccY", ["Recip-2", "Recip-4"] },
        { "1659453230_AccZ", ["no_fault"] },
        { "1659460430_AccX", ["Recip-2", "Recip-4"] },
        { "1659460430_AccY", ["Recip-2", "Recip-4"] },
        { "1659460430_AccZ", ["no_fault"] },
        { "1659467630_AccX", ["Recip-2", "Recip-4"] },
        { "1659467630_AccY", ["Recip-2", "Recip-4"] },
        { "1659467630_AccZ", ["no_fault"] },
        { "1659474831_AccX", ["Recip-2", "Recip-4"] },
        { "1659474831_AccY", ["Recip-2", "Recip-4"] },
        { "1659474831_AccZ", ["no_fault"] },
        { "1659482030_AccX", ["Recip-2", "Recip-4"] },
        { "1659482030_AccY", ["Recip-2", "Recip-4"] },
        { "1659482030_AccZ", ["no_fault"] },
    };

    private static readonly Dictionary<string, string[]> OilFuelSeparatorFaultCodes = new()
    {
        { "1659374030_AccX", ["RB-1"] },
        { "1659374030_AccY", ["RB-1"] },
        { "1659374030_AccZ", ["no_fault"] },
        { "1659381230_AccX", ["RB-1"] },
        { "1659381230_AccY", ["RB-1"] },
        { "1659381230_AccZ", ["no_fault"] },
        { "1659388431_AccX", ["RB-1"] },
        { "1659388431_AccY", ["RB-1"] },
        { "1659388431_AccZ", ["no_fault"] },
        { "1659395630_AccX", ["RB-1"] },
        { "1659395630_AccY", ["no_fault"] },
        { "1659395630_AccZ", ["no_fault"] },
        { "1659402830_AccX", ["RB-1"] },
        { "1659402830_AccY", ["RB-1"] },
        { "1659402830_AccZ", ["no_fault"] },
        { "1659410030_AccX", ["RB-1"] },
        { "1659410030_AccY", ["RB-1"] },
        { "1659410030_AccZ", ["no_fault"] },
        { "1659417230_AccX", ["RB-1"] },
        { "1659417230_AccY", ["RB-1"] },
        { "1659417230_AccZ", ["no_fault"] },
        { "1659424431_AccX", ["RB-1"] },
        { "1659424431_AccY", ["RB-1"] },
        { "1659424431_AccZ", ["no_fault"] },
        { "1659431630_AccX", ["RB-1"] },
        { "1659431630_AccY", ["RB-1"] },
        { "1659431630_AccZ", ["no_fault"] },
        { "1659438831_AccX", ["RB-1"] },
        { "1659438831_AccY", ["RB-1"] },
        { "1659438831_AccZ", ["no_fault"] },
        { "1659446031_AccX", ["RB-1"] },
        { "1659446031_AccY", ["RB-1"] },
        { "1659446031_AccZ", ["no_fault"] },
        { "1659453230_AccX", ["RB-1"] },
        { "1659453230_AccY", ["RB-1"] },
        { "1659453230_AccZ", ["no_fault"] },
        { "1659460430_AccX", ["RB-1"] },
        { "1659460430_AccY", ["RB-1"] },
        { "1659460430_AccZ", ["no_fault"] },
        { "1659467630_AccX", ["RB-1"] },
        { "1659467630_AccY", ["RB-1"] },
        { "1659467630_AccZ", ["RB-1"] },
        { "1659474831_AccX", ["RB-1"] },
        { "1659474831_AccY", ["RB-1"] },
        { "1659474831_AccZ", ["no_fault"] },
        { "1659482030_AccX", ["RB-1"] },
        { "1659482030_AccY", ["RB-1"] },
        { "1659482030_AccZ", ["RB-1"] },
    };

    private static readonly Dictionary<string, string[]> AirBlower1FaultCodes = new()
    {
        { "1659374030_AccX", ["RB-1"] },
        { "1659374030_AccY", ["RB-1"] },
        { "1659374030_AccZ", ["no_fault"] },
        { "1659381230_AccX", ["RB-1"] },
        { "1659381230_AccY", ["RB-1"] },
        { "1659381230_AccZ", ["no_fault"] },
        { "1659388431_AccX", ["RB-1"] },
        { "1659388431_AccY", ["RB-1"] },
        { "1659388431_AccZ", ["no_fault"] },
        { "1659395630_AccX", ["RB-1"] },
        { "1659395630_AccY", ["no_fault"] },
        { "1659395630_AccZ", ["no_fault"] },
        { "1659402830_AccX", ["RB-1"] },
        { "1659402830_AccY", ["RB-1"] },
        { "1659402830_AccZ", ["no_fault"] },
        { "1659410030_AccX", ["RB-1"] },
        { "1659410030_AccY", ["RB-1"] },
        { "1659410030_AccZ", ["no_fault"] },
        { "1659417230_AccX", ["RB-1"] },
        { "1659417230_AccY", ["RB-1"] },
        { "1659417230_AccZ", ["no_fault"] },
        { "1659424431_AccX", ["RB-1"] },
        { "1659424431_AccY", ["RB-1"] },
        { "1659424431_AccZ", ["no_fault"] },
        { "1659431630_AccX", ["RB-1"] },
        { "1659431630_AccY", ["RB-1"] },
        { "1659431630_AccZ", ["no_fault"] },
        { "1659438831_AccX", ["RB-1"] },
        { "1659438831_AccY", ["RB-1"] },
        { "1659438831_AccZ", ["no_fault"] },
        { "1659446031_AccX", ["RB-1"] },
        { "1659446031_AccY", ["RB-1"] },
        { "1659446031_AccZ", ["no_fault"] },
        { "1659453230_AccX", ["RB-1"] },
        { "1659453230_AccY", ["RB-1"] },
        { "1659453230_AccZ", ["no_fault"] },
        { "1659460430_AccX", ["RB-1"] },
        { "1659460430_AccY", ["RB-1"] },
        { "1659460430_AccZ", ["no_fault"] },
        { "1659467630_AccX", ["RB-1"] },
        { "1659467630_AccY", ["RB-1"] },
        { "1659467630_AccZ", ["RB-1"] },
        { "1659474831_AccX", ["RB-1"] },
        { "1659474831_AccY", ["RB-1"] },
        { "1659474831_AccZ", ["no_fault"] },
        { "1659482030_AccX", ["RB-1"] },
        { "1659482030_AccY", ["RB-1"] },
        { "1659482030_AccZ", ["RB-1"] },
    };

    private static readonly Dictionary<string, string[]> AirBlower2FaultCodes = new()
    {
        { "1659374030_AccX", ["no_fault"] },
        { "1659374030_AccY", ["RB-2"] },
        { "1659374030_AccZ", ["no_fault"] },
        { "1659381230_AccX", ["no_fault"] },
        { "1659381230_AccY", ["RB-2"] },
        { "1659381230_AccZ", ["no_fault"] },
        { "1659388431_AccX", ["RB-2"] },
        { "1659388431_AccY", ["RB-2"] },
        { "1659388431_AccZ", ["no_fault"] },
        { "1659395630_AccX", ["RB-2"] },
        { "1659395630_AccY", ["no_fault"] },
        { "1659395630_AccZ", ["no_fault"] },
        { "1659402830_AccX", ["RB-2"] },
        { "1659402830_AccY", ["RB-2"] },
        { "1659402830_AccZ", ["no_fault"] },
        { "1659410030_AccX", ["RB-2"] },
        { "1659410030_AccY", ["RB-2"] },
        { "1659410030_AccZ", ["no_fault"] },
        { "1659417230_AccX", ["RB-2"] },
        { "1659417230_AccY", ["RB-2"] },
        { "1659417230_AccZ", ["no_fault"] },
        { "1659424431_AccX", ["RB-2"] },
        { "1659424431_AccY", ["RB-2"] },
        { "1659424431_AccZ", ["no_fault"] },
        { "1659431630_AccX", ["RB-2"] },
        { "1659431630_AccY", ["RB-2"] },
        { "1659431630_AccZ", ["no_fault"] },
        { "1659438831_AccX", ["RB-2"] },
        { "1659438831_AccY", ["RB-2"] },
        { "1659438831_AccZ", ["no_fault"] },
        { "1659446031_AccX", ["RB-2"] },
        { "1659446031_AccY", ["RB-2"] },
        { "1659446031_AccZ", ["no_fault"] },
        { "1659453230_AccX", ["RB-2"] },
        { "1659453230_AccY", ["RB-2"] },
        { "1659453230_AccZ", ["no_fault"] },
        { "1659460430_AccX", ["RB-2"] },
        { "1659460430_AccY", ["RB-2"] },
        { "1659460430_AccZ", ["no_fault"] },
        { "1659467630_AccX", ["RB-2"] },
        { "1659467630_AccY", ["RB-2"] },
        { "1659467630_AccZ", ["RB-2"] },
        { "1659474831_AccX", ["RB-2"] },
        { "1659474831_AccY", ["RB-2"] },
        { "1659474831_AccZ", ["no_fault"] },
        { "1659482030_AccX", ["RB-2"] },
        { "1659482030_AccY", ["RB-2"] },
        { "1659482030_AccZ", ["no_fault"] },
    };

    private static readonly Dictionary<string, string[]> TurbineFaultCodes = new()
    {
        { "1659374030_AccX", ["no_fault"] },
        { "1659374030_AccY", ["no_fault"] },
        { "1659374030_AccZ", ["no_fault"] },
        { "1659381230_AccX", ["no_fault"] },
        { "1659381230_AccY", ["no_fault"] },
        { "1659381230_AccZ", ["no_fault"] },
        { "1659388431_AccX", ["no_fault"] },
        { "1659388431_AccY", ["no_fault"] },
        { "1659388431_AccZ", ["no_fault"] },
        { "1659395630_AccX", ["no_fault"] },
        { "1659395630_AccY", ["no_fault"] },
        { "1659395630_AccZ", ["no_fault"] },
        { "1659402830_AccX", ["no_fault"] },
        { "1659402830_AccY", ["no_fault"] },
        { "1659402830_AccZ", ["no_fault"] },
        { "1659410030_AccX", ["no_fault"] },
        { "1659410030_AccY", ["no_fault"] },
        { "1659410030_AccZ", ["no_fault"] },
        { "1659417230_AccX", ["no_fault"] },
        { "1659417230_AccY", ["no_fault"] },
        { "1659417230_AccZ", ["no_fault"] },
        { "1659424431_AccX", ["no_fault"] },
        { "1659424431_AccY", ["no_fault"] },
        { "1659424431_AccZ", ["no_fault"] },
        { "1659431630_AccX", ["no_fault"] },
        { "1659431630_AccY", ["no_fault"] },
        { "1659431630_AccZ", ["no_fault"] },
        { "1659438831_AccX", ["no_fault"] },
        { "1659438831_AccY", ["no_fault"] },
        { "1659438831_AccZ", ["no_fault"] },
        { "1659446031_AccX", ["no_fault"] },
        { "1659446031_AccY", ["no_fault"] },
        { "1659446031_AccZ", ["no_fault"] },
        { "1659453230_AccX", ["no_fault"] },
        { "1659453230_AccY", ["no_fault"] },
        { "1659453230_AccZ", ["no_fault"] },
        { "1659460430_AccX", ["no_fault"] },
        { "1659460430_AccY", ["no_fault"] },
        { "1659460430_AccZ", ["no_fault"] },
        { "1659467630_AccX", ["no_fault"] },
        { "1659467630_AccY", ["no_fault"] },
        { "1659467630_AccZ", ["no_fault"] },
        { "1659474831_AccX", ["no_fault"] },
        { "1659474831_AccY", ["no_fault"] },
        { "1659474831_AccZ", ["no_fault"] },
        { "1659482030_AccX", ["no_fault"] },
        { "1659482030_AccY", ["no_fault"] },
        { "1659482030_AccZ", ["no_fault"] },
    };

    private static readonly Dictionary<string, string[]> DieselGeneratorFaultCodes = new()
    {
        { "1659374030_AccX", ["no_fault"] },
        { "1659374030_AccY", ["no_fault"] },
        { "1659374030_AccZ", ["no_fault"] },
        { "1659381230_AccX", ["no_fault"] },
        { "1659381230_AccY", ["no_fault"] },
        { "1659381230_AccZ", ["no_fault"] },
        { "1659388431_AccX", ["no_fault"] },
        { "1659388431_AccY", ["no_fault"] },
        { "1659388431_AccZ", ["no_fault"] },
        { "1659395630_AccX", ["no_fault"] },
        { "1659395630_AccY", ["no_fault"] },
        { "1659395630_AccZ", ["no_fault"] },
        { "1659402830_AccX", ["no_fault"] },
        { "1659402830_AccY", ["no_fault"] },
        { "1659402830_AccZ", ["no_fault"] },
        { "1659410030_AccX", ["no_fault"] },
        { "1659410030_AccY", ["no_fault"] },
        { "1659410030_AccZ", ["no_fault"] },
        { "1659417230_AccX", ["no_fault"] },
        { "1659417230_AccY", ["no_fault"] },
        { "1659417230_AccZ", ["no_fault"] },
        { "1659424431_AccX", ["no_fault"] },
        { "1659424431_AccY", ["no_fault"] },
        { "1659424431_AccZ", ["no_fault"] },
        { "1659431630_AccX", ["no_fault"] },
        { "1659431630_AccY", ["no_fault"] },
        { "1659431630_AccZ", ["no_fault"] },
        { "1659438831_AccX", ["no_fault"] },
        { "1659438831_AccY", ["no_fault"] },
        { "1659438831_AccZ", ["no_fault"] },
        { "1659446031_AccX", ["no_fault"] },
        { "1659446031_AccY", ["no_fault"] },
        { "1659446031_AccZ", ["no_fault"] },
        { "1659453230_AccX", ["no_fault"] },
        { "1659453230_AccY", ["no_fault"] },
        { "1659453230_AccZ", ["no_fault"] },
        { "1659460430_AccX", ["no_fault"] },
        { "1659460430_AccY", ["no_fault"] },
        { "1659460430_AccZ", ["no_fault"] },
        { "1659467630_AccX", ["Recip-1"] },
        { "1659467630_AccY", ["no_fault"] },
        { "1659467630_AccZ", ["no_fault"] },
        { "1659474831_AccX", ["Recip-1"] },
        { "1659474831_AccY", ["Recip-1"] },
        { "1659474831_AccZ", ["no_fault"] },
        { "1659482030_AccX", ["Recip-1"] },
        { "1659482030_AccY", ["Recip-1"] },
        { "1659482030_AccZ", ["no_fault"] },
    };
}